UtilFunctions
__TOC__ UtilFunction provides functions that are used in multiple modules. In the module you can find functions that solve different needs which are all listed below. Power of two checking This function check if a number is power of two. This function is from sms-tools package. Wav Reading This function read a sound file (in .wav) and convert it in to a normalized floating point array. it returns to the sampling rate of file. This function is from sms-tools package. Wav Playing This function plays a sound file (in .wav) using OS calls. This function is from sms-tools package. Wav Writing This function write a sound file (in .wav) from an array with the sound and the sampling rate. This function is from sms-tools package. Peak Detection This function detects the location of spectral peaks of a frame. It needs the spectrum of a signal and a threshold. This function is from sms-tools package. Length of File This function return the length of a file in kbits. File Writing This function writes a variable to a file using the bits designed. It is intended to work in a similar way to MATLAB's 'fwrite' function. File Reading This function reads values a determined bit-length from a file. It is intended to work in a similar way to MATLAB's 'fread' function. Open Stream This function initializes the Stream as a BitString BitStream. Flush Stream This function flushes whatever is left in the global stream. Therefore if there were non-Byteable bits, it zero-pad them to Byteable and write them to the file. Signal to Noise Ratio This function calculates the total Signal to Noise Ratio (SNR) of the input and que output and a graph of SNR over time using a window determined. Bark This function convert a lineal frequency specified in hertz to bark scale. Bin to Bark This function convert the fft bin to bark scale, it uses the fft length and the sampling frequency. This function uses the function BARK. Schroeder This function calculates the masking spectrum for a given frequency and SPL with Schroeder function. 10log_{10} F(dz) = 15.81 + 75(dz + 0.474) - 75(1+(dz + 0.474)^2)^{1/2} It uses the sampling frequency, the frame length, the frequency peak location in hertz and the difference between the peak and the mask levels in dB. This function uses the function BARK. Midtread Quantizer This function quantize a signal in number of levels that we assign. it uses the signal and the number of bits that we want to use. Midtread Quantizer 2 This function is a more advanced function based in Midtread quantizer. It can quantize arrays and also check if there has been overlab (therefore some normalisation should be made). Midtread Dequantizer This function dequantize a signal quantized in number of levels that we assign. it uses the signal and the number of bits that we want to use. Modified Discrete Cosine Transform This function returns the Modified Discrete Cosine Transform of a signal. It needs a vector of a signal. Inverse Modified Discrete Cosine Transform This function returns the Inverse of Discrete Cosine Transform of a signal. It needs a vector of Discrete Cosine Transform of a signal. Bitpool Encoder This function quantizes the MDCT of a frame with the bits indicated at the 'bit_alloc'. It uses the MDCT of a frame, the sampling frequency, the frame length and bit_alloc (an array containing the bits designed for each band). It returns the quantized gain and the quantized MDCT. Enframe This function split a signal in to frames. We can choose a type of window to enframe each frame and the overlapping. Bit allocation This function allocates bits to each band given a certain bitrate (from which a bitpool will be generated). It is based on the SPL 'y' which for the perceptual model is the SMR. For Bands is just the signal SPL.